package cn.t17.appsys.service.impl;

import cn.t17.appsys.dao.DataDictionaryMapper;
import cn.t17.appsys.entity.DataDictionary;
import cn.t17.appsys.service.DataDictionaryService;
import cn.t17.appsys.vo.DataDictionaryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * DataDictionaryServiceImpl class
 *
 * @author Administrator
 * @date 2021/9/16
 */
@Service
public class DataDictionaryServiceImpl implements DataDictionaryService {

    @Autowired
    private DataDictionaryMapper dataDictionaryMapper;

    @Override
    public List<DataDictionaryVO> listByTypeCode(String typeCode) {
        List<DataDictionary> dataDictionaries =
                dataDictionaryMapper.listByTypeCode(typeCode);

        // 把 DataDictionary 转为 vo 对象
        List<DataDictionaryVO> dataDictionaryVOS = new ArrayList<>();
        for (DataDictionary dictionary : dataDictionaries) {
            DataDictionaryVO vo = new DataDictionaryVO();
            vo.setValueId(dictionary.getValueId());
            vo.setValueName(dictionary.getValueName());

            dataDictionaryVOS.add(vo);

        }
        return dataDictionaryVOS;
    }

}
